package tech.yunqian.slim.framework.web;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum Response {
    UNKNOWN(0, "unknown"),
    OK(1, "ok"),
    FAILED(2, "failed"),
    NOT_FOUND(3, "not found"),
// schema start
    SCHEMA_NOT_LOADED(101, "schema not loaded"),
    SCHEMA_PROCESSING_ERROR(102, "schema processing error"),
    SCHEMA_MISMATCH(103, "schema mismatch"),
// schema end
// user start
    LOG_IN_REQUIRED(201, "log in required"),
    LOGIN_FAILED(202, "login failed"),
    NOT_LOGGED_IN(203, "not logged in"),
    USER_DISABLED(204, "user disabled"),
    SESSION_EXPIRED(205, "session expired"),
    PREMISSION_DENIED(206, "permission denied"),
    USER_NOT_FOUND(207, "user not found"),
    USERNAME_EXISTS(208, "username exists"),
    USER_EMAIL_EXISTS(209, "user email exists"),
    USER_MOBILE_EXISTS(210, "user mobile exists"),
    USER_INCORRECT_PASSWORD(211, "incorrect password"),
// user end
// role start
    ROLE_NOT_FOUND(301, "role not found"),
    ROLE_NAME_EXISTS(302, "role name exists"),
// role end
    BOUNDARY(65535, "unknown");
    private Integer code;
    private String message;

    public AjaxResult toAjaxResult() {
        return toAjaxResult(null);
    }

    public AjaxResult toAjaxResult(Object data) {
        AjaxResult result = null;
        if (this == OK) {
            result = AjaxResult.success(this.getMessage(), data);
        } else {
            result = AjaxResult.error(this.getMessage(), data);
        }
        return result;
    }
}